/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2024/9/5
 * Time: 18:24
 */

#ifndef IDATAHANDLE_H
#define IDATAHANDLE_H

#include <map>
#include <memory>
#include <string>
#include <vector>

struct UserInfo {
    std::string name;
    std::string id;
};
using UserInfoSPtr = std::shared_ptr<UserInfo>;
using UserInfoVec = std::vector<UserInfoSPtr>;

struct GroupInfo {
    std::string name;
    std::string id;

    enum Type
    {
        None,
        Creator,
        Admin,
        Normal
    };

    // <ID,<Type,UserInfo>>
    std::map<std::string, std::pair<Type, UserInfoSPtr>> members;
};
using GroupInfoSPtr = std::shared_ptr<GroupInfo>;
using GroupInfoVec = std::vector<GroupInfoSPtr>;



class IDataHandle
{
public:
#pragma region User interface
    virtual ~IDataHandle() = default;

    virtual bool AddUser(const UserInfoSPtr & _info) = 0;

    virtual bool RemoveUser(const std::string & _id) = 0;

    virtual UserInfoSPtr FindUser(const std::string & _id) = 0;
#pragma endregion

#pragma region Group Interface

    virtual bool AddGroup(const GroupInfoSPtr & _info) = 0;

    virtual bool RemoveGroup(const std::string & _id) = 0;

    virtual GroupInfoVec FindGroupWithNameLike(const std::string & _name) = 0;

    virtual GroupInfoVec FindGroupWithIDLike(const std::string & _id) = 0;

    virtual bool JoinGroup(const std::string & _group_id, const std::string & _user_id) = 0;

    virtual bool ExitGroup(const std::string & _group_id, const std::string & _user_id) = 0;

    virtual bool ModifyGroupMemberRole(const std::string & _group_id, const std::string & _user_id,GroupInfo::Type _type) = 0;

    virtual GroupInfo::Type UserType(const std::string & _group_id, const std::string & _user_id) = 0;

    virtual bool MemberIsExist(const std::string & _group_id, const std::string & _user_id) = 0;

    virtual UserInfoVec Members(const std::string & _group_id) = 0;
#pragma endregion
};

using IDataHandleSPtr = std::shared_ptr<IDataHandle>;
#endif//IDATAHANDLE_H
